const mysql  = require('mysql')

const mysqlconfig = require('../../config/config')

const connection = mysql.createConnection(mysqlconfig.mysqlconfig)

connection.connect(function(err){
    if(err){
        return console.error(err)
    }else {
        console.log('mysql success');
    }
})

const query = (sql)=>{
    return new Promise((resolve, reject) => {
        connection.query(sql, function (error, results, fields) {
            if (error){
                reject (error)
                return
            }
            resolve(results)
          });
    })
}

module.exports = query